package com.zzz.offer.isPalindrome;

public class Solution {

    public static void main(String[] args) {
        System.out.println(new Solution().isPalindrome(666));
    }

    public boolean isPalindrome(int x) {
        if(x<0) return false;
        if(x<10) return true;

        int index = 0;
        int maxSize = 10;
        int[] packet = new int[maxSize];
        int parse = x;
        while(parse > 0) {
            int indexNum = parse % 10;
            if(index == 0 && indexNum == 0) {
                return false;
            }
            parse = parse / 10;
            packet[index] = indexNum;
            index++;
        }

        for(int i=0; i<index; i++) {
            if(packet[i] != packet[index-i-1]) {
                return false;
            }
        }
        return true;
    }

    public boolean isPalindrome2(int x) {
        if(x < 0) return false;

        if(x < 10) return true;

        if(x > 10 && x % 10 == 0) return false;

        int y = 0;
        int mid = x;
        while (mid > 0) {
            y = 10 * y + mid % 10;
            mid /= 10;
        }

        return y == x;
    }
}
